home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: in1.uu.net!tellab5!news
- From: Joe Toth <toth@tellabs.com>
- Subject: Re: Q: realloc->free?
- X-Nntp-Posting-Host: sunh25
- Content-Type: text/plain; charset=us-ascii
- Message-ID: <1996Jan15.205832.2456@tellab5.tellabs.com>
- Sender: news@tellab5.tellabs.com (News)
- Content-Transfer-Encoding: 7bit
- Organization: Tellabs Operations, Inc.
- References: <4daa2e$oh5@axe.netdoor.com> <4de8uv$48j@bs33n.staffs.ac.uk>
- Mime-Version: 1.0
- Date: Mon, 15 Jan 1996 20:58:32 GMT
- X-Mailer: Mozilla 1.1 (X11; U; SunOS 4.1.3 sun4c)
- X-Url: news:4de8uv$48j@bs33n.staffs.ac.uk
-
- cm4bctrd@bs47c.staffs.ac.uk (Wildfire) wrote:
- [snip]
-
- >realloc() does no free()ing, as far as I know, since the contents of
- >memory are unchanged.
-
- The following is an excerpt from the HPUX man page;
-
- : realloc changes the size of the block pointed to by ptr to size bytes
- : and returns a pointer to the (possibly moved) block. Existing
- : contents are unchanged up to the lesser of the new and old sizes. If
- : ptr is a NULL pointer, realloc behaves like malloc for the specified
- : size. If size is zero and ptr is not a NULL pointer, the object it
- : points to is freed and NULL is returned.
- ^^^^^^^^
-
- >I would really like someone who properly knows about this to confirm or
- >correct what I'm saying.
-
- Test I've done seem to show that there are four situations;
-
- 1) the equivalence of the two operations
- a = realloc ( 0, size );
- and
- a = malloc ( size );
- 2) the equivalence of the two operations;
- a = realloc ( b, 0 );
- and
- a = free ( b );
- 3) the new size can fit such that the pointer doesn't have to change
- and there no free performed.
- a = realloc ( b, size );
- where ( a == b ) = TRUE after the operation.
- 4) the new sized allocation will not fit where the original was and the
- original space is freed and the new space is allocated elsewhere (moved),
- where ( a == b ) = FALSE after the operation
-
- Of course, as usual, this is all system dependent.
-
- >Wildfire :-)
-
- Hope this helps.
-
- _ _ ___ --------------------------+---------------------------------
- | / _ | Joseph G. Toth Jr. | Tellabs Operations, Inc.
- \_| \_/ | | toth@tellabs.com
-
- > Every program has at least one bug and can be shortened by at least
- > one instruction -- from which, by induction, it is evident that every
- > program can be reduced to one instruction that does not work.
- > -- Ken Arnold
-
-